package co.uk.j_wp.games.topdowngame.tile;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;

import javax.imageio.ImageIO;

import co.uk.j_wp.games.topdowngame.Game;

public class TileMap {

	private int numtileWidth;
	private int numtileHeight;
	private Tile[][] tiles;

	public TileMap(String s) throws IOException {
		InputStream is = getClass().getResourceAsStream(s);
		BufferedImage image = ImageIO.read(is);
		numtileWidth = image.getWidth() / Game.TILE_SIZE;
		numtileHeight = image.getHeight() / Game.TILE_SIZE;
		tiles = new Tile[numtileHeight][];
		for (int y = 0; y < numtileHeight; y++) {
			tiles[y] = new Tile[numtileWidth];
			for (int x = 0; x < numtileWidth; x++) {
				tiles[y][x] = new Tile(image.getRGB(x*Game.TILE_SIZE, y*Game.TILE_SIZE, Game.TILE_SIZE, Game.TILE_SIZE,null, 0,Game.TILE_SIZE));
			}
		}
	}

	public Tile get(int i, int j) {
		return tiles[j][i];
	}
	public int[] getTileColors(int i , int j){
		return tiles[j][i].colors;
	}
}
